
<%--
  Created by IntelliJ IDEA.
  User: yingg_000
  Date: 2015/7/15
  Time: 14:20
  To change this template use File | Settings | File Templates.
--%>

<%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="utf-8" %>

<!DOCTYPE HTML>
<html>

<head>
    <title>施工管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>
    道路管理 <span class="c-gray en">&gt;</span>
    掘地施工
</nav>
<div class="pd-20">
    <div class="text-c">

        <input type="text"  placeholder="开工时间" style="width:120px" class="input-text"id="startTime">&nbsp;&nbsp;&nbsp;
        <input type="text"  placeholder=" 施工编号" style="width:120px" class="input-text"id="number">&nbsp;&nbsp;&nbsp;
        <input type="text" placeholder=" 施工地点" style="width:120px" class="input-text" id="titlename">&nbsp;&nbsp;&nbsp;
        <button id="doSearch" class="btn btn-success radius"><i class="Hui-iconfont">&#xe665;</i> 搜索
        </button>

    </div>
    <table id="searchTable" style="margin-top:5px">
        <tr style="background-color:#a6c9e2;height:42px">
                 <th colspan="10" scope="col" >
                        <span class="l"><a href="javascript:;" onClick="digroad_edit()"
                                           class="btn btn-primary radius" ><i class="Hui-iconfont">&#xe600;</i> 添加</a>

             <a href="javascript:;" onClick="deldig()" class="btn btn-danger radius" ><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a></span>
        </th>
        </tr>
        <tr>
            <th w_num="line" width="3%;"></th>
            <th w_check="true" w_index="id" width="3%;"></th>
            <th w_index="roadname" width="17%">施工地点</th>
            <th w_index="licencenum" w_sort="licencenum" width="17%">施工编号</th>
            <th w_index="constructstarttime" w_sort="constructstarttime" width="8%">开工时间</th>
            <th w_index="constructovertime" w_sort="constructovertime" width="8%">完工时间</th>
            <th w_index="constructovertime"w_render="setStatus" width="5%">状态</th>

            <th w_index="digmessage" width="29%">施工原因</th>

            <th w_index="digtype" width="5%">施工类型</th>
            <th w_render="operate" width="5%">操作</th>
        </tr>
    </table>
</div>
</body>
</html>
<%@include file="../../head-ui.jsp" %>
<script type="text/javascript">
    var gridObj;
    $(function () {

        gridObj = $.fn.bsgrid.init('searchTable', {
            url: '<%=request.getContextPath()%>/back/digroad/list.do',
            // autoLoad: false,
            pageSizeSelect: true,
            pagingLittleToolbar: false,
            stripeRows: true,
            pageSize: 20,
            rowHoverColor: true,
            stripeRows: true,
            displayBlankRows: false
        });

        $("#doSearch").click(function () {
            doSearch();
        })
    });
    function doSearch() {
        var searchParames = {roadname: encodeURI($("#titlename").val()),
            startTime:$("#startTime").val(),number:$("#number").val()};
        gridObj.search(searchParames);
    }

    function operate(record, rowIndex, colIndex, options) {

        var str =  "<a title='编辑' href='javascript:void(0)' " +
                "onClick=\"digroad_edit('" + record.id + "')\" class='ml-5' style='text-decoration:none'><i class='Hui-iconfont'>&#xe6df;</i></a>" +
                "<a title='删除' href='javascript:void(0)' " +
                "onClick=\"digroad_del('" + record.id + "')\" class='ml-5' style='text-decoration:none'><i class='Hui-iconfont'>&#xe6e2;</i></a>";


        if(record.status=='0'){

            str +=  "<a title='结束施工' href='javascript:void(0)' " +
                    "onClick=\"digroad_end('" + record.id + "')\" class='ml-5' style='text-decoration:none'>" +
                    "<i class='Hui-iconfont'> &#xe615;</i></a>" ;
        }
        return str;

    }
    function setStatus(record, rowIndex, colIndex, options) {
        var status ="";
        if(record.status==0){
            status = "施工中";

        }else if(record.status==1){
            status = "已结束";

        } else if(record.status==2){
            status = "<span style='color:red'>已超时</span>";

        }else if(record.status==3){
            status = "未施工";


        }
        return status;

    }

    function deldig() {
        var ids = gridObj.getCheckedValues('id');
        if (ids == null || ids == "") {
            layer.msg('请选择需要删除的工程!', {icon: 1, time: 1000});

        } else {
            digroad_del(ids.join(","));
        }

    }
    function digroad_del(id) {
        layer.confirm('确认要删除吗？', function () {
            $.ajax({
                url: '<%=request.getContextPath()%>/back/digroad/delete.do',
                type: 'POST',
                data: "id="+id,
                success: function (res) {
                    if (res == "true") {
                        doSearch();
                        layer.msg('已删除!', {icon: 1, time: 1000});
                    } else {
                        layer.msg('删除失败!', {icon: 1, time: 1000});
                    }
                }
            })
        });
    }


    function digroad_edit(id) {
        if(id!=null) {
            var index = layer.open({
                type: 2,
                title: '施工信息编辑',
                content: "<%=request.getContextPath()%>/back/digroad/edit_page.do?id=" + id
            });
            layer.full(index);
        }else{
            var index = layer.open({
                type: 2,
                title: '施工信息添加',
                content: "<%=request.getContextPath()%>/back/digroad/edit_page.do"
            });
            layer.full(index);
        }

    }
    function digroad_end(id){
        layer.confirm('是否确认结束该段施工？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            $.ajax({
                url:'<%=request.getContextPath()%>/back/digroad/updateStatus.do?id='+id,
                type:'get',
                success:function(data){
                    layer.close();
                    if(data=='true'){
                        layer.alert('该施工已经结束!', {icon: 1});
                        doSearch();
                    }else{
                        layer.alert('该施工状态修改失败!', {icon: 2});
                    }

                }
            })

        }, function(){
            layer.close();
        });

    }
</script>